import { component$ } from '@builder.io/qwik';
import { routeLoader$ } from "@builder.io/qwik-city";


export default component$(() => {
    const dadJokeSignal = useDadJoke();
    return (
      <section class="section bright">
        <p>{dadJokeSignal.value.joke}</p>
      </section>
    );
});

export const useDadJoke = routeLoader$(async () => {
    const response = await fetch('https://icanhazdadjoke.com/', {
      headers: { Accept: 'application/json' },
    });
    console.log(response);
    greet('nihao');
    return (await response.json()) as {
      id: string;
      status: number;
      joke: string;
    };
  });

  export const greet = function(params:string,name:string='aiya') {
    console.log(params,name);
  }

  export function identity(arg: number): number {
    return arg;
}

 export const enum Direction{
    UP,
    DOWN,
    RIGHT,
    LEFT
 }

 export interface Tree<T>{
    value:T;
    left:Tree<T>;
    right:Tree<T>;
 }
